package controller

import(
	"golang.org/x/net/websocket"	
	"github.com/bugfan/logrus"    	
	_ "github.com/bugfan/logrus/hooks/file"
	"time"		
)
var(
	BlockData map[string]chan int
	RealtimeData string
)
func init(){
	BlockData=make(map[string]chan int,1)
}
func Overview(ws *websocket.Conn){
	logrus.Println("--> 连接了一个: ",ws.Request().RemoteAddr)
	block:=make(chan int,1)
	BlockData[ws.Request().RemoteAddr]=block
	defer func(){
		logrus.Println("<-- 退了一个: ",ws.Request().RemoteAddr)
		delete(BlockData,ws.Request().RemoteAddr)
		ws.Close()	
	}()
	for {
		if err:=websocket.Message.Send(ws,RealtimeData);err!=nil{
			logrus.Error("消息推送失败: ",err)
			break
		}
		<- block
	}
}
func DisBlock(args ...*map[string]chan int){
	time.Sleep(1e3)
	for _,obj:=range args{
		go func(o *map[string]chan int){
			for _,v:=range *o{
				go func(b chan int){
					b <- 0
				}(v)
			}
		}(obj)
	}
}